package com.transcoachapp.adapter;

import java.util.ArrayList;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.transcoachapp.BusStations;
import com.transcoachapp.FerryTimeActivity;
import com.transcoachapp.R;
import com.transcoachapp.data.Ferry;

public class FerryAdapter extends ArrayAdapter<Ferry>{
	private Activity context;
	private ArrayList<Ferry> items;
	
	public FerryAdapter(Context context, int textViewResourceId,
			ArrayList<Ferry> objects) { 
		super(context, textViewResourceId);
		this.items = objects;
		this.context = (Activity) context;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (this.items != null)
		      return this.items.size();
		return 0;
	}
	@Override
	public Ferry getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.items.get(arg0);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{   // Ordinary view in Spinner, we use android.R.layout.simple_spinner_item
		
		final Ferry ferry  = getItem(position);
		View bsdRow = context.getLayoutInflater().inflate(R.layout.ferry_line, null);
		TextView textView = (TextView) bsdRow.findViewById(R.id.ferryName);
        textView.setText(ferry.getName());
	    bsdRow.setClickable(true);
		bsdRow.setOnClickListener(new OnClickListener() {			
			public void onClick(View arg0) {
				Intent intent = new Intent();
                intent.setClass(context, FerryTimeActivity.class);
                intent.putExtra("ferryId", Integer.toString(ferry.getId()));
                intent.putExtra("name", ferry.getName());
				context.startActivity(intent);	
			}
		});

		return bsdRow;
	}
}

